﻿Option Explicit Off
Option Strict Off
Imports Microsoft.VisualBasic.Devices
Imports System.Text.RegularExpressions
Public Class addupdelForm
    Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer
    'This allows clicking of the system tray icon and it restores the form
    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim CP As CreateParams = MyBase.CreateParams
            CP.Style = &HA0000
            Return CP
        End Get
    End Property
    'Sub to initialize the Numbers Only form
    Private Sub M_onkeydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Console.WriteLine(e.KeyCode)
    End Sub
    'Handles close procedure
    Private Sub closeLabel_Click(sender As Object, e As EventArgs) Handles closeLabel.Click, ExitToolStripMenuItem.Click, ExitToolStripMenuItem1.Click, ExitToolStripMenuItem2.Click
        Helpdesk.Close()
    End Sub
    'Handles minimize procedure
    Private Sub minimizeLabel_Click(sender As Object, e As EventArgs) Handles minimizeLabel.Click, MinimizeToolStripMenuItem.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub
    'Handles mousedown on the menu
    Private Sub helpDeskMenu_MouseDown(sender As Object, e As MouseEventArgs) Handles helpDeskMenu.MouseDown, Me.MouseDown, helpdeskTitle.MouseDown, byteSpeedIcon.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End Sub
    'Changes mouse cursor to normal
    Private Sub helpdeskTitle_MouseLeave(sender As Object, e As EventArgs) Handles helpdeskTitle.MouseLeave
        If Me.Cursor = Cursors.SizeAll Then
            Me.Cursor = Cursors.Default
        End If
    End Sub
    'Allows the mouse to move the form
    Private Sub helpDeskMenu_MouseMove(sender As Object, e As MouseEventArgs) Handles helpDeskMenu.MouseMove, Me.MouseMove, helpdeskTitle.MouseMove, byteSpeedIcon.MouseMove
        If drag Then
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
        End If
    End Sub
    'Shuts down the dragging events
    Private Sub helpDeskMenu_MouseUp(sender As Object, e As MouseEventArgs) Handles helpDeskMenu.MouseUp, Me.MouseUp, helpdeskTitle.MouseUp, byteSpeedIcon.MouseUp
        drag = False
        If Me.Cursor = Cursors.SizeAll Then
            Me.Cursor = Cursors.Default
        End If
    End Sub
    'Render initialize sub for MyRenderer Class
    Public Sub New()
        Try
            InitializeComponent()
            helpDeskMenu.Renderer = New MyRenderer()
        Catch ex As Exception
        End Try
    End Sub
    'Changes the color of the menus and mouse over effects
    Public Class MyRenderer
        Inherits ToolStripProfessionalRenderer
        Protected Overloads Overrides Sub OnRenderMenuItemBackground(ByVal e As ToolStripItemRenderEventArgs)
            Try
                Dim rc As New Rectangle(Point.Empty, e.Item.Size)
                Dim c As Color = IIf(e.Item.Selected, Color.DarkGray, Color.DimGray)
                Using brush As New SolidBrush(c)
                    e.Graphics.FillRectangle(brush, rc)
                End Using
            Catch ex As Exception
            End Try
        End Sub
    End Class
    'Click the move menu item will bring the mouse to the middle of the helpdesk menu and change the
    'mouse coursor to a sizeall
    Private Sub MoveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MoveToolStripMenuItem.Click
        Dim xValue As Integer
        Dim yValue As Integer
        xValue = Me.Location.X + (Me.Width / 2)
        yValue = Me.Location.Y + (helpDeskMenu.Height / 2)
        Windows.Forms.Cursor.Position = New Point(xValue, yValue)
        Me.Cursor = Cursors.SizeAll
    End Sub
    'Handles systray icon once the menu item has been clicked
    Private Sub Helpdesk_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        If HideInSystrayToolStripMenuItem.Checked Then
            Try
                If Me.WindowState = FormWindowState.Minimized Then
                    Me.Visible = False
                    systrayPop.Visible = True
                    If Helpdesk.clicked = False Then
                        systrayPop.ShowBalloonTip(3000, "Helpdesk - Search", "You've minimized this software to the" _
                                                   & " sytem tray.  Click this balloon to stop this message" _
                                                   & " from displaying again", ToolTipIcon.Info)
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub
    'Handles if the balloon tooltip or close even happens on the systray popup
    Private Sub systrayPop_BalloonTipClicked(sender As Object, e As EventArgs) Handles systrayPop.BalloonTipClicked, systrayPop.BalloonTipClosed
        Helpdesk.clicked = True
    End Sub
    'Handles if tray icon is double clicked
    Private Sub systrayPop_DoubleClick(sender As Object, e As EventArgs) Handles systrayPop.DoubleClick, ShowToolStripMenuItem.Click
        Me.Visible = True
        Me.WindowState = FormWindowState.Normal
        Me.BringToFront()
        systrayPop.Visible = False
    End Sub
    'Handles the Quick Search function menu item
    Private Sub QuickSearchToolStripMenuItem_Click_1(sender As Object, e As EventArgs) Handles FunctionsToolStripMenuItem.Click
        Me.Hide()
        If Me.HideInSystrayToolStripMenuItem.Checked = True Then
            Me.systrayPop.Visible = False
            Helpdesk.HideInSystrayToolStripMenuItem.Checked = True
        Else
            Helpdesk.systrayPop.Visible = False
        End If
        Helpdesk.Show()
        Helpdesk.BringToFront()
        Helpdesk.Top = Me.Top
        Helpdesk.Left = Me.Left
    End Sub
    'Start the function of this form now
    Private Sub Helpdesk_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Removes image margin in context menu
        iconClickContext.ShowImageMargin = False
        'Uses Numbers only form
        a = New NumberOnlyTextbox(Me.rmaQSchTBox, True, True, AddressOf M_onkeydown)
        Me.systrayPop.Visible = False

        'end of cosmetic things

    End Sub

End Class
